<%@page import="Entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>个人信息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<link rel="shortcut icon" type="image/x-icon" href="logo.jpg" />
  </head>
  
  <body>
    <%
     User user =(User) session.getAttribute("user");
      if(user==null){
  	 	 request.getRequestDispatcher("login.jsp").forward(request,response);
  	 }
  		 String psw =user.getPwd();
  		 String stuNum =user.getUid();
  		int id= user.getUtype();
  		String name =user.getUname();
  		String phone =user.getTel();
  
	  	String iden = "";
	  	if(id==3)
	  		iden = "学生";
	  	else if(id ==2)
	  		iden = "老师";
	  	else if(id==1)
	  		iden = "管理员";
  	
   %>
    <div>
    	<div style="margin-top: 30px;margin-left: 20px;">
    	<h3 style="font-family: 楷体;margin: 20px ;">个人信息管理</h3>
    	<a class="btn btn-primary " style="margin: 20px auto 0 40px;" data-toggle="modal" data-target="#myModal">修改密码</a><br>
    	<%
    		if(id==1){
    		%>
    		<a type="button" class="btn btn-primary" data-toggle="collapse" 
			    data-target="#demo" style="margin: 10px auto 0 40px;">
			     管理员选项
			</a>    
			<div id="demo" class="collapse" style="">
			   <a class="btn btn-default" href="search_userInfor.jsp"  style="margin: 4px auto 0 40px;">查询用户信息</a>
			</div>
    		
    		<% 
    		}
    		else{
    		
    		}
    	 %>
    	
    	</div>
    	<div style="width: 500px;height: 400px; margin: 100px auto;">
    		<form class="form-horizontal" role="form"  name="form"  method="post">
				  <div class="form-group">
				    <label  class="col-sm-2 control-label">昵称</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" placeholder="请输入昵称" value="<%=name %>" id="new_name" name="new_name" style="width: 400px;">
				    </div>
				  </div>
				   <div class="form-group">
				    <label  class="col-sm-2 control-label">工号</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control"  value="<%=stuNum %>" readonly="readonly" style="width: 400px;">
				    </div>
				  </div>
				   <div class="form-group">
				    <label  class="col-sm-2 control-label">身份</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control"  value="<%=iden %>" readonly="readonly" style="width: 400px;">
				    </div>
				  </div>
				  <div class="form-group">
				    <label  class="col-sm-2 control-label">手机号</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" placeholder="请输入手机号" value="<%=phone %>" id="phone" style="width: 400px;">
				    </div>
				  </div>
				 
				
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button type="submit"  id="submit" class="btn btn-default" onclick="checking()">修改个人信息</button>
				    </div>
				  </div>
			</form>
				
		</div>
    </div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改密码</h4>
            </div>
            <div class="modal-body">
				<div style="width: 500px;height: 400px;margin: 10px auto;">
    		<form class="form-horizontal" role="form"  name="form"  method="post" action="ChangeServlet">
				  <div class="form-group">
				    <label for="lastname" class="col-sm-2 control-label"> 原密码</label>
				    <div class="col-sm-10">
				      <input type="password" class="form-control" id="old_pwd" name="old_pwd" placeholder="请输入原密码" style="width: 400px;">
				    </div>
				  </div>
				   <div class="form-group">
				    <label for="lastname" class="col-sm-2 control-label"> 新密码</label>
				    <div class="col-sm-10">
				      <input type="password" class="form-control"  placeholder="密码长度为6-12位" name="new_pwd" id="new_pwd" style="width: 400px;">
				    </div>
				  </div>
				   <div class="form-group">
				    <label for="lastname" class="col-sm-2 control-label"> 再次输入新密码</label>
				    <div class="col-sm-10">
				      <input type="password" class="form-control"  placeholder="请再次输入新密码" name="renew_pwd" id="renew_pwd" style="width: 400px;">
				    </div>
				  </div>
			</form>
		</div>
			</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" id="submit" class="btn btn-primary" onclick="checkingpsw(<%=psw%>)" data-dismiss="modal">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
    <script type="text/javascript">
    	function checking(){
    		  var new_name = document.getElementById("new_name").value;
			  var phone = document.getElementById("phone").value;
			  var  partten = /^1[3,5,8]\d{9}$/;
			  if (new_name ==null || new_name =="")
			  {
			    alert("请输入姓名！");
			    return false;
			  }else if (phone ==null || phone =="")
			  {
			    alert("请输入手机号！");
			    return false;
			  }else if (!partten.test(phone))
			  {
			    alert("请输入正确的手机号！");
			    return false;
			  }else
			  {
			  	alert("个人信息修改成功！");
			  }  
		  }
    </script>
    <script type="text/javascript">
    	function checkingpsw(psw){
			  var old_pwd = document.getElementById("old_pwd").value;
			  var new_pwd = document.getElementById("new_pwd").value;
			  var renew_pwd = document.getElementById("renew_pwd").value;
			  var str ="";
			  str = new_pwd;
			  var len = str.length;
			  if (old_pwd ==null || old_pwd =="")
			  {
			    alert("请输入原密码！");
			    return false;
			  }else if (new_pwd ==null || new_pwd =="")
			  {
			    alert("请输入新密码！");
			    return false;
			  }else if (renew_pwd ==null || renew_pwd =="")
			  {
			    alert("请再次输入新密码！");
			    return false;
			  }else if(new_pwd!=renew_pwd)
			  {
			  	alert("两次密码输入不一致，请重新输入！");
			    return false;
			  }else if(len<6||len>20)
			  {
			  	alert("密码长度应该在6-10之内，请重新输入！");
			    return false;
			  }else if(old_pwd != psw)
			  {
			  	alert("密码错误，请重新输入！");
			    return false;
			  }else
			  {
			  	alert("密码修改成功！");
			  }  
		  }
    </script>
    
  </body>
</html>
